/**
* ...
* @author Ludo
* @version 0.1
*/

import clases.MadParser.XMLParser.XMLParser;
import clases.utils.MadDate;

class clases.MadParser.PlayByPlay.MadCuarto {


	/* Variable que tiene el nombre del cuarto*/
	public var name:String;
	
	/* Array de jugadas en ese cuarto */
	private var _arrayPlay:Array;
	
	/**
	 * Constructor de la clase
	 */
	public function MadCuarto(objCuarto:Object,team1:String, team2:String, quarter:Number) {
		
		name = objCuarto.quarter;
		
		
		_arrayPlay = new Array();
		
;
		if(objCuarto.action == undefined)
		{
			return;
		}
		
		if(objCuarto.action[0] == undefined)
		{
			var copy = objCuarto.action;
			objCuarto.action = new Array();
			objCuarto.action.push(copy);
		}
		
		for(var i=0;i<=objCuarto.action.length-1;i++)
		{
			var act = objCuarto.action[i];
			var action:Object = new Object();
			action.min = act.minute;
			action.desc = act.desc;
			action.playerName = act.playerName;
			action.teamName = act.teamName;
			action.pointsTeam1 = act.pointsTeam1;
			action.pointsTeam2 = act.pointsTeam2;			
			action.code = act.id;
			var score:String = new String();
			if(act.pointsTeam1)
			{
				score = act.pointsTeam1;
			}
			else
			{
				score = "-";
			}
			

			score += " ";
			
			if(act.pointsTeam2)
			{
				score += act.pointsTeam2;
			}
			else
			{
				score += "-";
			}
			action.score = score;
			
			action.team1 = "";
			action.team2 = "";
			
			if (action.code == "2FGAB")
			{
				action.code = "2FGA";
			}
			else if (action.code == "3FGAB")
			{
				action.code = "3FGA";
			}
		

			if(_level0[action.code] != undefined)
			{
				action.desc = _level0[action.code];
			}
			
			if(action.teamName == team1)
			{
				if((action.playerName != "") && (action.playerName != undefined))
				{
					action.team1 = action.playerName + "<br>"
				}
				action.team1 += action.desc;
			}
			if(action.teamName == team2)
			{
				if((action.playerName != "") && (action.playerName != undefined))
				{
					action.team2 = action.playerName + "<br>"
				}
				action.team2 += action.desc;
			}
			
			if (action.code == "EP")
			{
				action.code = "EP_" + quarter;
			}
			else if (action.code == "FV")
			{
				action.code = "AG";
			}				
			else if (action.code == "RV")
			{
				action.code = "CM";
			}				
			
			
			trace(action.team1 + ":" + action.team2);
			
			_arrayPlay.push(action);
		}
	}
	
	public function get arrayActions():Array
	{
		trace("Voy a devolver");
		trace(_arrayPlay.length);
		return _arrayPlay;
	}


	
}	
